#!/bin/bash

usage() {
    echo "Usage: $0 [OPTIONS] CHR START END > new_session.xml"
    echo "Generate IGV session file for given genomic position."
    echo
    echo "Options:"
    echo "  -h, --help    Display this help message and exit."
    echo
    echo "Arguments:"
    echo "  CHR           Chromosome identifier (1,2,...,22)."
    echo "  START         Start position."
    echo "  END           End position."
    exit 1
}

if [[ $# -eq 0 ]] || [[ "$1" == "-h" ]] || [[ "$1" == "--help" ]]; then
    usage
fi

if [[ $# -ne 3 ]]; then
    echo "Error: Invalid number of arguments."
    usage
fi

sed -e "s/xxCHRxx/${1}/g" \
-e "s/xxSTARTxx/${2}/g" \
-e "s/xxENDxx/${3}/g" archaic4-proto.xml